﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TalentPools.Model;
using System.Data;
using System.Data.SqlClient;
namespace TalentPools.DAL
{
    /// <summary>
    /// 用户注册
    /// </summary>
    public class ResigeerService
    {
        #region 注册个人信息
        /// <summary>
        /// 注册个人信息
        /// </summary>
        /// <param name="user">用户信息类</param>
        /// <returns></returns>
        public bool resigerUser(Person_BaseMeans user)
        {
            string sql = "insert into UserInfo (username,password,name,sex,birthday,marriage,card,politicsStatus,HKPlace,city,currentAddress,zipCode,cellphone,phoneCode,email,homePage) values (@username,@password,@name,@sex,@birthday,@marriage,@card,@politicsStatus,@HKPlace,@city,@currentAddress,@zipCode,@cellphone,@phoneCode,@email,@homePage)";
            SqlParameter[] par = { new SqlParameter("@username",user.username),
                                 new SqlParameter("@name",user.name),
                                 new SqlParameter("@sex",user.sex),
                                 new SqlParameter("@birthday",user.birthday),
                                 new SqlParameter("@marriage",user.marriage),
                                 new SqlParameter("@card",user.card),
                                 new SqlParameter("@politicsStatus",user.politicsStatus),
                                 new SqlParameter("@HKPlace",user.HKPlace),
                                 new SqlParameter("@city",user.city),
                                 new SqlParameter("@currentAddress",user.currentAddress),
                                 new SqlParameter("@zipCode",user.zipCode),
                                 new SqlParameter("@cellphone",user.cellphone),
                                 new SqlParameter("@phoneCode",user.phoneCode),
                                 new SqlParameter("@email",user.email),
                                 new SqlParameter("@homePage",user.homePage)
                                                           };

            int i = DBHelper.ExecuteNonQuery(CommandType.Text, sql, par);
            if (i > 0)
            {
                return true;
            }
            return false;
        }
        #endregion
        #region 寻找用户最大的编号
        /// <summary>
        /// 寻找用户最大的编号
        /// </summary>
        /// <returns></returns>
        public long getMaxno()
        {
            string sql = "select max(userNo) from UserInfo";

            long i = (long)SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql);
            return i;
        }
        #endregion
        #region 查找用户名的个数
        /// <summary>
        /// 查找用户名的个数
        /// </summary>
        /// <param name="name">注册时填的用户名</param>
        /// <returns></returns>
        public int getNameCount(string name)
        {
            string sql = "select count(*) from UserInfo where Name=@name";
            SqlParameter[] par = { new SqlParameter("@name", name) };
            int i = (int)SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql, par);
            return i;
        }
        #endregion

    }
}
